package com.iwhalecloud.citybrain.flow.platform.manager.application.service;

import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowTitleExpressionResultRepository;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class FlowCustomTitleProcessor implements ProcessInstanceStartPostProcessor {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RepositoryService repositoryService;


    @Autowired
    private FlowTitleExpressionResultRepository flowTitleExpressionResultRepository;

    @Override
    public void process(ExecutionEntity executionEntity) {
        final String processDefinitionId = executionEntity.getProcessDefinitionId();
        String deployId = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult().getDeploymentId();
        flowTitleExpressionResultRepository.batchInsert(deployId, executionEntity);
    }
}
